package com.dlkw.easyroom.compiler.classkeeper;

import com.dlkw.easyroom.common.Consts;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;

import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public abstract class BaseClass {
    private final TypeElement typeElement;

    public BaseClass(TypeElement element) {
        this.typeElement = element;
    }

    public final JavaFile toJavaFile() {
        ClassName className = ClassName.get(typeElement);
        String simpleName = className.simpleName();
        TypeSpec.Builder builder = TypeSpec.classBuilder("$$" + simpleName + "Keeper").addModifiers(Modifier.PUBLIC, Modifier.FINAL);
        this.fillTypeBuilder(builder);
        return JavaFile.builder(Consts.EASY_ROOM_PACKAGE, builder.build()).build();
    }

    protected abstract void fillTypeBuilder(TypeSpec.Builder builder);
}
